package com.zzptc.zy.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.os.Bundle;
import android.util.Log;

import com.bumptech.glide.util.LogTime;
import com.zzptc.zy.myapplication.adapter.MyRecyclerviewAdapter;
import com.zzptc.zy.myapplication.databinding.ActivityMainBinding;
import com.zzptc.zy.myapplication.entity.RecipeModel;
import com.zzptc.zy.myapplication.entity.ResultsBean;
import com.zzptc.zy.myapplication.service.MyAppService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";


    Retrofit r = new Retrofit.Builder()
            .baseUrl("https://liyuankun.cn/")
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    MyAppService myAppService = r.create(MyAppService.class);
    ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_main);  // ActivityMainBinding binding;


        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(MainActivity.this);
        binding.rvRecipe.setLayoutManager(linearLayoutManager);
        getAllRecipte();

    }

    private void getAllRecipte() {
        Call<RecipeModel> recipe = myAppService.getRecipe(1000);

        recipe.enqueue(new Callback<RecipeModel>() {
            @Override
            public void onResponse(Call<RecipeModel> call, Response<RecipeModel> response) {
                List<ResultsBean> list;
                RecipeModel re = response.body();
                list = re.getResults();
                MyRecyclerviewAdapter myRecyclerviewAdapter = new MyRecyclerviewAdapter(list, MainActivity.this);
                binding.rvRecipe.setAdapter(myRecyclerviewAdapter);

            }


            @Override
            public void onFailure(Call<RecipeModel> call, Throwable t) {
                Log.d(TAG, "onFailure: " + t.getMessage());


            }
        });
    }
}







        // new MyRecyclerviewAdapter(,MainActivity.this);//实参？！   形式参数在adpter里面
        //binding.rvRecipe.setAdapter();


